function handleChangeCesiumContainerToolPosition(isShow) {
  // 复位视角 放大 缩小
  getDom(
    () => document.getElementsByClassName('cesium-viewer-toolbar'),
    ($CesiumViewerToolbar) => resetToolRight($CesiumViewerToolbar, isShow, 'domStyles'),
  );

  // 地图 & 工具
  getDom(
    () => document.getElementsByClassName('toolBarRight'),
    ($CesiumViewerToolbar) => resetToolRight($CesiumViewerToolbar, isShow, 'toolBarRightStyles'),
  );

  // 按下鼠标左键并向四周拖拽不释放 可修改视图角度。双击:重置视图。
  getDom(
    () => document.querySelectorAll('#navigationDiv > div'),
    ($NavigationDiv) => resetToolRight($NavigationDiv, isShow, 'domStyles'),
  );

  // nwh3d-位置
  getDom(
    () => document.querySelectorAll('#mapView-nwh3d-location'),
    ($MapViewNwh3dLocation) => resetToolRight($MapViewNwh3dLocation, isShow),
  );
}

const resetToolRight = (dom, isShow, type) => {
  const domStyles = {
    'margin-right': '-5px',
    transition: 'margin-right 0.45s',
  };

  const toolBarRightStyles = {
    marginTop: '10px',
    'margin-right': '-5px',
    transition: 'margin-right 0.45s',
  };

  if (isShow) {
    domStyles['margin-right'] = '340px';
    toolBarRightStyles['margin-right'] = '340px';
  }

  if (dom) {
    for (const item in domStyles) {
      if (item && domStyles[item]) {
        if (type === 'domStyles') {
          // 复位视角 放大 缩小
          // 按下鼠标左键并向四周拖拽不释放 可修改视图角度。双击:重置视图。
          dom.style[item] = domStyles[item];
        } else if (type === 'toolBarRightStyles') {
          // 地图 & 工具
          dom.style[item] = toolBarRightStyles[item];
        } else {
          // nwh3d-位置
          dom.style.right = isShow ? '340px ' : '0px';
          dom.style.transition = 'right 0.45s';
        }
      }
    }
  }
};

const getDom = (fn = () => null, callback = () => {}) => {
  let _dom = fn();
  if (_dom && _dom[0]) {
    callback(_dom[0]);
    return;
  } else {
    const _index = setInterval(() => {
      if (fn) {
        _dom = fn();
        if (_dom && _dom[0]) {
          clearInterval(_index);
          callback(_dom[0]);
        }
      }
    }, 600);
  }
};

export { handleChangeCesiumContainerToolPosition, resetToolRight, getDom };
